package com.wqt;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @ProjectName: ybxy6
 * @Titile: TreeMapDemo
 * @Author: wqt
 * @Description: TODO
 */
public class TreeMapDemo {
    public static void main(String[] args) {
        test2();

    }

    private static void test1() {
        TreeMap<Student, String> treeMap = new TreeMap<>();
        treeMap.put(new Student("小1", 19), "上海");
        treeMap.put(new Student("小2", 22), "深圳");
        treeMap.put(new Student("小3", 18), "四川");
        treeMap.put(new Student("小4", 20), "北京");
        treeMap.put(new Student("小5", 21), "广州");

        treeMap.forEach((k,v)-> System.out.println(k + ":" + v));
    }
    public static void test2() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //倒序
                return o2.getAge()-o1.getAge();
            }
        });

        treeMap.put(new Student("小1", 19), "上海");
        treeMap.put(new Student("小2", 22), "深圳");
        treeMap.put(new Student("小3", 18), "四川");
        treeMap.put(new Student("小4", 20), "北京");
        treeMap.put(new Student("小5", 21), "广州");

        treeMap.forEach((k,v)-> System.out.println(k + ":" + v));

    }

}